﻿#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
using namespace std;

enum Colour
{
	RED,
	BALCK
};

template<class T>
struct RBTreeNode
{
	T _data;
	RBTreeNode<T>* _left;
	RBTreeNode<T>* _right;
	RBTreeNode<T>* _parent;
	Colour _col;

	RBTreeNode(const T& data)
		:_data(data)
		, _left(nullptr)
		, _right(nullptr)
		,_parent(nullptr)
	{}
};
template <class K,class T, class KeyOfT>
class RBtree
{
	typedef RBTreeNode<T> Node;
public:
	bool insert(const T& data)
	{
		if (_root == nullptr)
		{
			_root = new Node(data);
			_root->_col = _BLANK;
			return true;
		}

		KeyOfT kot;
		Node* cur = _root;
		Node* parent = nullptr;

		while (cur)
		{
			if (kot(cur->_data) > kot(data))
			{
				parent = cur;
				cur = cur->_left;
			}
			else if (kot(cur->_data)<kot(data))
			{
				parent = cur;
				cur = cur->_right;
			}
			else
			{
				return false;
			}

			cur = new Node(data);
			Node* newnode = cur;
			// 新增结点。颜⾊给红⾊
			cur->_col = RED;

			if (kot(parent->_data) < kot(data))
			{
				parent->_right = cur;
			}
			else
			{
				parent->_left = cur;
			}
			cur->_parent = parent;
			//...
			return true;


		}
	}
private:
	Node* _root = nullptr;
};
